package cn.pfund.interceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import cn.pfund.Constants;
import cn.pfund.entity.CompanyinfoType;
import cn.pfund.service.CompanyinfoTypeService;
import cn.pfund.service.IndexImageService;
import cn.pfund.service.NavigationService;

/**
 * @description 全局拦截器
 * @author zhaominglei qq:351024274，专注于网站、app和游戏开发。
 * @date 2016年6月29日
 */
public class GlobalInterceptor extends HandlerInterceptorAdapter {
    @Resource(name="navigationService")
    private NavigationService navigationService;
    @Resource(name="indexImageService")
    private IndexImageService indexImageService;
    @Resource(name="companyinfoTypeService")
    private CompanyinfoTypeService companyinfoTypeService;
    
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
		if (modelAndView != null) {
			modelAndView.addObject("cdnServerIp", Constants.CDN_SERVER_IP);
			modelAndView.addObject("navigations", navigationService.getAllNavigation());
			modelAndView.addObject("footXsslCompanyinfoTypes", companyinfoTypeService.getAllCompanyinfoType(CompanyinfoType.COMPANYINFOTYPE_XSSL_BELONGTO));
			modelAndView.addObject("footXsslcompanyinfoType", CompanyinfoType.COMPANYINFOTYPE_XSSL_BELONGTO);
			modelAndView.addObject("footAqbzCompanyinfoTypes", companyinfoTypeService.getAllCompanyinfoType(CompanyinfoType.COMPANYINFOTYPE_AQBZ_BELONGTO));
			modelAndView.addObject("footAqbzcompanyinfoType", CompanyinfoType.COMPANYINFOTYPE_AQBZ_BELONGTO);
			modelAndView.addObject("footYwzzCompanyinfoTypes", companyinfoTypeService.getAllCompanyinfoType(CompanyinfoType.COMPANYINFOTYPE_YWZZ_BELONGTO));
			modelAndView.addObject("footYwzzcompanyinfoType", CompanyinfoType.COMPANYINFOTYPE_YWZZ_BELONGTO);
			modelAndView.addObject("indexImages", indexImageService.getAllIndexImage());
		}
		super.postHandle(request, response, handler, modelAndView);
	}
}
